package com.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.project.bean.ExpertBean;
import com.project.dao.ExpertDao;
import com.project.service.ExpertService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 专家
 */

@Service
@Transactional
public class ExpertServiceImpl extends ServiceImpl<ExpertDao, ExpertBean> implements ExpertService {
    /**
     * 分页查询所有专家信息
     * @param pageNo
     * @param pageSize
     * @return
     */
    @Override
    public IPage<ExpertBean> findAllExpert(int pageNo, int pageSize) {
        Page<ExpertBean> page = new Page<>(pageNo, pageSize);
        IPage<ExpertBean> iPage = this.page(page);
        return iPage;
    }

    /**
     * 添加专家
     * @param expertBean
     */
    @Override
    public void addExpert(ExpertBean expertBean) {
        this.baseMapper.addExpert(expertBean);

    }

    /**
     * 根据专家id查询详细信息
     * @param expertId
     * @return
     */
    @Override
    public ExpertBean findId(int  expertId) {
        return this.baseMapper.findId(expertId);
    }

    /**
     * 根据专家id去修改专家电话、职务、工作单位、邮箱
     * @param expertId
     * @param expertTel
     * @param expertDuty
     * @param expertWork
     * @param expertEmail
     */
    @Override
    public void updateExpert(int expertId, String expertTel, String expertDuty,
                             String expertWork, String expertEmail) {
//        ExpertBean expertBean = new ExpertBean();
//        expertBean.setExId(expertId);
//        expertBean.setExTel(expertTel);
//        expertBean.setExDuty(expertDuty);
//        expertBean.setExWork(expertWork);
//        expertBean.setExEmail(expertEmail);
//        this.updateById(expertBean);
        this.baseMapper.updateExpert(expertId,expertTel,expertDuty,expertWork,expertEmail);
    }


    /**
     * 根据专家id删除专家
     *
     * @param expertId
     */
    @Override
    public void delExpert(int expertId) {
        this.removeById(expertId);

    }

    /**
     * 根据专家姓名，专长，工作单位模糊查询专家信息
     *
     * @param pageNo
     * @param pageSize
     * @param expertName
     * @param expertSpecialty
     * @param expertWork
     * @return
     */
    @Override
    public IPage<ExpertBean> findName(int pageNo, int pageSize,
                                      String expertName, String expertSpecialty,
                                      String expertWork) {
        Page<ExpertBean> page = new Page<>(pageNo,pageSize);
        QueryWrapper wrapper = new QueryWrapper();
        if (expertName!=null && !expertName.equals("")){
            wrapper.like("f_exName",expertName);
        }
        if (expertSpecialty!=null && !expertSpecialty.equals("")){
            wrapper.like("f_exSpecialty",expertSpecialty);
        }
        if (expertWork!=null && !expertWork.equals("")){
            wrapper.like("f_exWork",expertWork);
        }
        IPage<ExpertBean> iPage = this.page(page,wrapper);
        return iPage;
    }

    @Override
    public List<ExpertBean> findAllList() {
        return this.list();
    }
}
